package com.tanhua.server.controller;

import com.tanhua.model.domain.Result;
import com.tanhua.model.vo.ResultVo;
import com.tanhua.model.vo.TestSoulVo;
import com.tanhua.server.service.ResultService;
import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    @Autowired
    private ResultService resultService;

    /**
     * 获取问卷
     * @return
     */
    @GetMapping
    public ResponseEntity questionList(){
        List<TestSoulVo> vo = testSoulService.questionList();
        return ResponseEntity.ok(vo);
    }

    /**
     * 提交问卷
     * @param map
     * @return
     */
    @PostMapping
    public ResponseEntity submitTestSoul(@RequestBody Map map){
        String id = resultService.saveResult(map);
        return ResponseEntity.ok(id);
    }

    /**
     * 返回解果
     * @param id
     * @return
     */
    @GetMapping("/report/{id}")
    public ResponseEntity selectResult(@PathVariable Integer id){
        ResultVo resultVo = resultService.selectResult(id);
        return ResponseEntity.ok(resultVo);
    }
}
